﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefMaterialStore" :model="stateMaterialStore.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MaterialId_FormItem" prop="Entity.MaterialId" :label="$t('message.autotrans._Model_MaterialStore_Material')">
            <el-select v-model="stateMaterialStore.vmModel.Entity.MaterialId" clearable>
               <el-option v-for="item in stateMaterialStore.AllMaterials" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MinStore_FormItem" prop="Entity.MinStore" :label="$t('message.autotrans._Model_MaterialStore_MinStore')">
            <el-input v-model="stateMaterialStore.vmModel.Entity.MinStore" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_StoreQty_FormItem" prop="Entity.StoreQty" :label="$t('message.autotrans._Model_MaterialStore_StoreQty')">
            <el-input v-model="stateMaterialStore.vmModel.Entity.StoreQty" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MaxStore_FormItem" prop="Entity.MaxStore" :label="$t('message.autotrans._Model_MaterialStore_MaxStore')">
            <el-input v-model="stateMaterialStore.vmModel.Entity.MaxStore" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Expiration_FormItem" prop="Entity.Expiration" :label="$t('message.autotrans._Model_MaterialStore_Expiration')">
            <el-input v-model="stateMaterialStore.vmModel.Entity.Expiration" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_LastInBatch_FormItem" prop="Entity.LastInBatch" :label="$t('message.autotrans._Model_MaterialStore_LastInBatch')">
            <el-input v-model="stateMaterialStore.vmModel.Entity.LastInBatch" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_LastInStoreTime_FormItem" prop="Entity.LastInStoreTime" :label="$t('message.autotrans._Model_MaterialStore_LastInStoreTime')">
            <el-date-picker v-model="stateMaterialStore.vmModel.Entity.LastInStoreTime" type='date' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_LastOutStoreTime_FormItem" prop="Entity.LastOutStoreTime" :label="$t('message.autotrans._Model_MaterialStore_LastOutStoreTime')">
            <el-input v-model="stateMaterialStore.vmModel.Entity.LastOutStoreTime" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Pos_FormItem" prop="Entity.Pos" :label="$t('message.autotrans._Model_MaterialStore_Pos')">
            <el-input v-model="stateMaterialStore.vmModel.Entity.Pos" clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onSubmitMaterialStore"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseMaterialStore"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageWmsManagementMaterialStoreCreate;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { materialstoreApi } from '/@/api/wmsmanagement/materialstore';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefMaterialStore = ref();
const stateMaterialStore = reactive({
    vmModel: {
	  Entity:{
        MaterialId: null,
        MinStore: null,
        StoreQty: null,
        MaxStore: null,
        Expiration: null,
        LastInBatch: '',
        LastInStoreTime: undefined,
        LastOutStoreTime: null,
        Pos: '',
      },

	},
    
    AllMaterials: [] as any[],
});

// 取消
const onCloseMaterialStore = () => {
    closeDialog();
};

// 提交
const onSubmitMaterialStore = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefMaterialStore.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            materialstoreApi().add(stateMaterialStore.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/WmsManagement/MaterialStore/GetMaterialDocs',[],false).then(x=>{stateMaterialStore.AllMaterials = x});
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

